//
//  ByApiUserIndex.m
//  jinpuyiyuan_ios
//
//  Created by pro on 2017/12/14.
//  Copyright © 2017年 mc. All rights reserved.
//

#import "ByApiUserIndex.h"

#import "ByModelIndexBranch.h"      // 分院model

@implementation ByApiUserIndex
// 获取分院分页数据
+ (void)getBranchList:(ByNetParamsModel *)model
              success:(void(^)(ByNetBaseResult *result))success
              failure:(void(^)(ByNetBaseResult *result))failure{
    static NSString *apiType = @"By_Hosp_query";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%ld%d", (NSInteger)[NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
//    [params setObject:model.uid forKey:@"uid"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取分院列表";
           NSMutableDictionary *resDic = [[NSMutableDictionary alloc] init];
           NSMutableArray *tmp = [[NSMutableArray alloc] init];
           for (NSDictionary *dic in ((NSDictionary *)responseObject)[@"list"]) {
               ByModelIndexBranch *model = [[ByModelIndexBranch alloc] initContentWithDic:dic];
               [tmp addObject:model];
           }
           [resDic setObject:tmp forKey:@"list"];
           [resDic setObject:((NSDictionary *)responseObject)[@"count"] forKey:@"count"];
           result.data = resDic;
           result.notify_id = notifyID;
           
           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** %@ 获取分院列表: %@", apiType, error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert showFailureWithText:result.msg];
           }
       }];

}
@end
